<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html> 
<head>
<title>WordCount Sample</title>
<link rel="stylesheet" type="text/css" href="../../../docs/rotor.css">
</head>

<body>		


<h1> WordCount Sample</h1>


<h2>Sample Overview</h2>


<p>This sample offers an introduction to the base class library. It shows 
  how to create an application that opens multiple files (specified on the 
  command line) and counts each file's bytes, characters, words, and lines. The 
  results from each file and the total of all files are sent to the console. </p>


<p>The following classes are used by the sample:</p>


<ul>
  <li><b>I/O </b>
  <ul>
    <li><b>FileStream</b><ul>
    <li>Used for its file access. This 
    class is used to read to and write from files. </li>
  </ul>
    </li>
  </ul>
  <ul>
    <li><b>StreamWriter</b><ul>
    <li>Used when the 
    command-line arguments request that the output be sent to a file. The 
    <b>StreamWriter</b> is used in conjunction with a <b>FileStream</b> instance to format 
    text output to a file. </li>
  </ul>
    </li>
  </ul>
  <ul>
    <li><b>StreamReader</b><ul>
    <li>Used to read the 
    contents of a file for which the sample is counting words. The <b>StreamReader</b> is used 
    in conjunction with a <b>FileStream</b> instance to read text from a file. </li>
  </ul>
    </li>
  </ul>
  </li>
  <li><b>Collections</b><ul>
    <li><b>ArrayList</b><ul>
    <li>Used as a general collection class for 
    storing sets of objects. </li>
  </ul>
    </li>
  </ul>
  <ul>
    <li><b>SortedList</b><ul>
    <li>Used  as a collection class for storing 
    sets of objects in a sorted manner. </li>
  </ul>
    </li>
  </ul>
  <ul>
    <li><b>IEnumerator</b><ul>
    <li>Used directly to 
    enumerate over sets of objects. </li>
  </ul>
    </li>
  </ul>
  <ul>
    <li><b>IDictionaryEnumerator</b><ul>
    <li>Used directly 
    to enumerate over indexed sets of objects. </li>
  </ul>
    </li>
  </ul>
  </li>
</ul>
<h4>Usage</h4>

<blockquote>
  <pre>clix wordcount [-a] [-o] [-f&lt;output-pathname&gt;] [-c&lt;codepage&gt;] filename</pre>
</blockquote>
  <p>The following table shows the command-line options used by the sample.</p>
<table border="1" width="90%">
  <tr>
    <th width="33%">Option</th>
    <th width="67%">Description</th>
  </tr>
  <tr>
    <td width="33%"><b>-?</b></td>
    <td width="67%">Shows usage information.</td>
  </tr>
  <tr>
    <td width="33%"><b>-a </b></td>
    <td width="67%">Sorts word usage alphabetically.</td>
  </tr>
  <tr>
    <td width="33%"><b>-c</b></td>
    <td width="67%">Specifies the codepage to use to read the file.</td>
  </tr>
  <tr>
    <td width="33%"><b>-f:</b><i>outfile</i></td>
    <td width="67%">Sends output to outfile instead of the console.</td>
  </tr>
  <tr>
    <td width="33%"><b>-o</b></td>
    <td width="67%">Sorts word usage by occurrence and then alphabetically.</td>
  </tr>
  </table>

<h2>Sample Source and Build Output Locations</h2>


<p>The sample source is found in sscli20\samples\utilities\wordcount.</p>


<p>The source file is:</p>


<ul class="none">
  <li><a href="wordcount.cs">wordcount.cs</a></li>
</ul>


<p>The build output location is %_NTTREE%\samples\utilities\wordcount.&nbsp; 
The output file is an executable assembly named wordcount.exe.</p>


<h2>Building the Sample</h2>


<p>All samples are built from the buildall script.&nbsp;  </p>


<p>You can also build all the 
samples by switching to the root of the sample directory, sscli20\samples, and typing 
<code>build -c</code>.</p>


<p>You can build this specific sample  by switching to the sample directory and typing 
<code>build -c</code>.</p>


<h2>Running the Sample</h2>


<p>These steps require that the Shared Source CLI (SSCLI) be already built and 
functional.</p>


<ol>
  <li>Run  env.bat. </li>
  <li>Switch to the %_NTTREE%\samples\utilities\wordcount directory.</li>
  <li>Type the following command:<blockquote>


<p>clix wordcount.exe <i>filename</i></p>


  </blockquote>


  </li>
</ol>
<blockquote>


<p>where <i>filename</i> is the name of the file in which to count words and 
lines.</p>


</blockquote>


<hr>


<p><i>Copyright (c) 2006 Microsoft Corporation. All rights reserved.</i></p>
</body> 
</html>